﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Drawing;
using System.Windows.Forms;
using System.Xml.Serialization;

namespace FortDoneQuicker
{
    public enum Action { None, Dig };

    public class Grid
    {
        public int nbRows;
        public int nbColumns;
        public List<List<Action>> actions;
        public List<Action> this[int i, int j]
        {
            get
            {
                int index = (i * nbColumns) + j;
                List<Action> a = actions[index];
                return a;
            }
        }

        public void saveXML()
        {
            serializeXML(this, "bla.xml");
        }
        public void loadXML()
        {
            Grid grid = (Grid)deserializeXML("bla.xml", this.GetType());

            nbRows = grid.nbRows;
            nbColumns = grid.nbColumns;
            actions = grid.actions;
        }
        private static void serializeXML(object o, string fileName)
        {
            using (FileStream fileStream = new FileStream(fileName, FileMode.Create))
            {
                XmlSerializer serializer = new XmlSerializer(o.GetType());
                serializer.Serialize(fileStream, o);
            }
        }
        private static object deserializeXML(string fileName, Type t)
        {
            using (FileStream fileStream = new FileStream(fileName, FileMode.Open))
            {
                XmlSerializer serializer = new XmlSerializer(t);
                return serializer.Deserialize(fileStream);
            }
        }
    }
}
